﻿
@{
    Layout = null;
}

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>WebUploader文件上传</title>
    <meta name="viewport" content="width=device-width" />
    <link href="/lib/webuploader/webuploader.css" rel="stylesheet" />
    <link href="/lib/webuploader/style_ccc.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="container">
        <!--头部，相册选择和格式选择-->
        <div id="uploader">
            <div class="queueList" style="width:680px;">
                <div id="filePicker"></div>
                <div id="filePicker2"></div><div class="uploadBtn" style="margin-left:0px; display:none;">开始上传</div>
            </div>
            <div>
                <img src="~/lib/webuploader/Delete.gif" title="删除" class="delete" style="display:none; cursor:pointer; position:absolute; top:8px; left:385px;" />
            </div>
            <div class="statusBar" style=" display:none;">
                <div class="progress">
                    <span class="text">0%</span>
                    <span class="percentage" style="display:none;"></span>
                </div>
                <div class="info"></div>
            </div>
        </div>
    </div>
    <script src="/lib/webuploader/jquery.js" type="text/javascript"></script>
    <script src="/lib/webuploader/webuploader-v0.1.6.js"></script>
    <script src="/lib/webuploader/upload_ccc.js" type="text/javascript"></script>
    <!--[if IE]>
    <script type="text/javascript">
        if (!window.console || !console.firebug) {
            var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

            window.console = {};
            for (var i = 0; i < names.length; ++i)
                window.console[names[i]] = function () { }
        }
    </script>
    <script src="https://cdn.bootcss.com/json2/20160511/json2.min.js"></script>
    <![endif]-->
    <script type="text/javascript">
        window.Global = window.Global || {};
        Global.FileQueueds = [];
        Global.GetFileQueued = function (id) {
            var res = [];
            $.each(Global.FileQueueds, function (idx, row) {
                if (row.id == id) {
                    res = row;
                }
            })
            return res;
        };
    </script>
    <script type="text/javascript">
        $(function () {
            var _chunk = 0;
            WebUploader.Uploader.register({
                "before-send-file": "beforeSendFile",
                "before-send": "beforeSend",
                "after-send-file": "afterSendFile"
            }, {
                beforeSendFile: function (file) {
                    console.info('beforeSendFile', Global.FileQueueds, file);
                    $.each(Global.FileQueueds, function (idx, row) {
                        if (row.id == file.id) {
                            _chunk = row.chunk;
                            //alert(_chunk);
                            //alert(decodeURIComponent(row.savePath));  //upload.js line:201
                            //alert(file.size);
                            //alert(row.md5);
                        }
                    });
                    //_chunk = Global.FileQueueds.find(f=>f.id == file.id).chunk;
                },
                beforeSend: function (block) {
                    var blob = block.blob.getSource(),
                        deferred = $.Deferred();
                    console.info('blob', block);
                    //根据md5与服务端匹配，如果重复，则跳过。 webuploader-v0.1.6.js Line:3375 CuteFile
                    if (block.chunk < _chunk) {
                        deferred.reject();
                    }
                    else {
                        deferred.resolve();
                    }
                    return deferred.promise();
                },
                afterSendFile: function (file) {
                }
            });
        });
    </script>
    <script type="text/javascript">
        //这是上传文件成功后(文件已合并)的回调事件
        function UploadSuccessCallback(file, md5, savePath) {
            console.info('UploadSuccessCallback', file);
            var data = {
                Name: file.name,
                Size: file.size,
                Extension: file.ext
            };
            var jsonData = JSON.stringify(data);
            console.info('提交文件', jsonData);
            $.ajax({
                url: '/FileUpload/AddUploadRecord',
                type: 'post',
                data: { data: jsonData, md5: md5 },
                dataType: 'json',
                success: function (data) {
                    console.info(data);
                    if (data.code < 0) {
                        alert(data.errmsg);
                    }
                    else {
                        //alert("OK");
                        alert('文件[' + file.name + ']已上传并提交，请耐心等待管理员的审核');
                        alert("文件路径：" + decodeURIComponent(savePath));
                        //alert(file.name);
                        //alert("MD5:" + md5);
                        $('.pop-window0 .pop-close').click();
                    }
                }
            });
        };
    </script>
</body>
</html>